part of '../repository.dart';

class _CollectionListItemDtoFactory {
  const _CollectionListItemDtoFactory._internal();

  static const _instance = _CollectionListItemDtoFactory._internal();

  factory _CollectionListItemDtoFactory() {
    return _instance;
  }

  _CollectionListItemDto fromJson(Map<String, dynamic> json) {
    final type = json[_kCollectionListItemTypeKey] as String;

    switch (type) {
      case _kInbuiltCollectionTypeValue:
        return _InbuiltCollectionDto.fromJson(json);
      case _kInbuiltCollectionFolderTypeValue:
        return _InbuiltCollectionFolderDto.fromJson(json);
      case _kCustomCollectionTypeValue:
        return _CustomCollectionDto.fromJson(json);
      case _kCustomCollectionFolderTypeValue:
        return _CustomCollectionFolderDto.fromJson(json);
      default:
        throw UnimplementedError();
    }
  }

  _CollectionListItemDto fromEntity(CollectionListItem collectionListItem) {
    switch (collectionListItem) {
      case InbuiltCollection():
        return _InbuiltCollectionDto.fromEntity(collectionListItem);
      case InbuiltCollectionFolder():
        return _InbuiltCollectionFolderDto.fromEntity(collectionListItem);
      case CustomCollection():
        return _CustomCollectionDto.fromEntity(collectionListItem);
      case CustomCollectionFolder():
        return _CustomCollectionFolderDto.fromEntity(collectionListItem);
    }
  }
}
